home *** CD-ROM | disk | FTP | other *** search
- PROGRAM SingleHider;
-
- {$R SingleHider.Rsrc}
- {$U-}
-
- USES Memtypes,QuickDraw,OSIntf,ToolIntf,PackIntf;
-
- CONST
- itemOK = 3;
- itemCancel = 4;
- itemStat1 = 1;
- itemEdit1 = 2;
- itemHider = 5;
- itemHideIt = 6;
- itemMax = 6;
- VAR
- ihDialog: DialogPtr;
- itemHit: INTEGER;
- theType: INTEGER;
- theHdl: Handle;
- theBox: Rect;
- oldEditField: INTEGER;
- hidden: BOOLEAN;
- OnlyOne: BOOLEAN;
-
-
- PROCEDURE MyDrawItem(dlg: DialogPtr; theItem: INTEGER);
- VAR
- iType: INTEGER;
- iBox: Rect;
- iHdl: Handle;
- iIndex: INTEGER;
-
- BEGIN
- GetDItem(dlg, theItem, iType, iHdl, iBox);
- IF hidden THEN BEGIN
- PenMode(notPatBic);
- PenPat(gray);
- BackPat(gray);
- PaintRect(iBox);
- FrameRect(iBox);
-
- PenMode(patCopy);
- PenPat(black);
- BackPat(white);
- PenNormal;
- END;
- END;
-
-
- PROCEDURE HideEditItem(theDialog: DialogPtr; theItem: INTEGER);
- VAR
- iIndex: INTEGER;
- BEGIN
- OnlyOne := FALSE;
-
- (* Get the item information. *)
- GetDItem(theDialog, theItem, theType, theHdl, theBox);
-
- (* Is theItem the current editText item? *)
- IF DialogPeek(theDialog)^.EditField + 1 = theItem THEN BEGIN
- (* It is, so now we find the next editText item *)
- (* in the item list. Start with the one we are on.*)
- iIndex := theItem;
- REPEAT
- (* Increment to the next item, and make sure we *)
- (* don't run off the end of the item list. *)
- iIndex := iIndex + 1;
- IF iIndex > itemMax THEN iIndex := 1;
-
- (* If we're back to theItem, then we don't have *)
- (* another editText item. In this case, we'll *)
- (* just set the EditField to -1 to tell the *)
- (* Dialog Manager that we don't have _any_ *)
- (* editText items. *)
- IF iIndex = theItem THEN BEGIN
- (* Set a flag, so ShowEditItem knows to set *)
- (* this back. *)
- OnlyOne := TRUE;
- END ELSE
- GetDItem(theDialog, iIndex, theType, theHdl, theBox);
- UNTIL (OnlyOne OR (theType = editText));
-
- IF (NOT OnlyOne) THEN
- SelIText(theDialog, iIndex, 0, 0);
- END;
- GetDItem(theDialog, theItem, theType, theHdl, theBox);
- SetDItem(theDialog, theItem, statText, theHdl, theBox);
- oldEditField := DialogPeek(theDialog)^.EditField;
- DialogPeek(theDialog)^.EditField := -1;
- DrawDialog(theDialog);
- END;
-
-
- PROCEDURE ShowEditItem(theDialog: DialogPtr; theItem: INTEGER);
- BEGIN
- GetDItem(theDialog, theItem, theType, theHdl, theBox);
- SetDItem(theDialog, theItem, editText, theHdl, theBox);
-
- IF OnlyOne THEN
- DialogPeek(theDialog)^.EditField := oldEditField;
-
- DrawDialog(theDialog);
- END;
-
-
- BEGIN {main program}
- InitGraf (@thePort); {the big five inits}
- InitFonts;
- InitWindows;
- TEInit;
- InitDialogs (nil);
-
- hidden := FALSE;
-
- ihDialog := GetNewDialog(128, NIL, WindowPtr(-1));
- GetDItem(ihDialog, itemHider, theType, theHdl, theBox);
- SetDItem(ihDialog, itemHider, theType, @MyDrawItem, theBox);
- ShowWindow(ihDialog);
-
- itemHit := 0;
- WHILE ((itemHit <> itemOK) AND (itemHit <> itemCancel)) DO BEGIN
- ModalDialog(nil, itemHit);
- CASE itemHit OF
- itemHideIt: BEGIN
- GetDItem(ihDialog, itemHit, theType, theHdl, theBox);
- hidden := NOT hidden;
- IF hidden THEN BEGIN
- SetCtlValue(ControlHandle(theHdl), 1);
- HideEditItem(ihDialog, itemEdit1);
- END ELSE BEGIN
- SetCtlValue(ControlHandle(theHdl), 0);
- ShowEditItem(ihDialog, itemEdit1);
- END;
- END;
- END;
- END;
-
- DisposDialog(ihDialog);
- END.
-